#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>

/*
 * ./ledtest /dev/vernon_spi0 Hex
 */
int main(int argc, char **argv)
{
	int fd;
	u_int16_t rel;
	int res;
	
	/* 1. 判断参数 */
	if (argc != 3) 
	{
		printf("Usage: %s <dev> <value>\n", argv[0]);
		return -1;
	}

	/* 2. 打开文件 */
	fd = open(argv[1], O_RDWR);
	if (fd == -1)
	{
		printf("can not open file %s\n", argv[1]);
		return -1;
	}

	/* 3. 写文件 */
	if (argv[2] != NULL)
	{
		sscanf(argv[2], "%x", &rel);
		res = write(fd, &rel, sizeof(rel));
		if(res < 0)
		{
			printf("write error!");
		}
		printf("write content: %x\n", rel);
	}
	else
	{
		printf("invalied str");
	}
	
	close(fd);
	
	return 0;
}


